home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 4.3 KB | 160 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/17/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPConfirmUsers
-
- SUPERCLASS: CPPPeriodicTask
-
- This C++ class goes through our list of nodes, checking to
- make sure that they are all still on the network. If
- they are not, it deletes them from the list.
-
- ********************************************************************/
-
- #include <CPPTaskManager.h>
- #include <CPPNodeInfo.h>
- #include <CPPObjectList.h>
- #include <CPPConfirmTask.h>
- #include "CPPUserList.h"
- #include "CPPConfirmUsers.h"
- #include <CPPSound.h>
- #include "MyGlobals.h"
- #include <MemoryTools.h>
- #include <StringTools.h>
-
- extern CPPUserList *gUserList;
- extern CPPSound *gLogonSound;
- extern PrefsData gPrefsInfo;
-
- void ConfirmCompletionProc (CPPObject *TheTask);
- extern void SetStatusMessage (StringPtr NewMessage, Boolean MakeCopy);
- extern StringPtr ShortName (CPPNodeInfo *theNode);
-
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPConfirmUsers::CPPConfirmUsers (CPPTaskManager *TaskManager,
- long minPeriod,
- Boolean deleteWhenDone) :
- CPPPeriodicTask (TaskManager, minPeriod,
- deleteWhenDone)
- {
- nodeList = NULL;
- confirmTask = NULL;
- whichNode = 0;
- this->confirmTask = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPConfirmUsers::~CPPConfirmUsers (void)
- {
- if (confirmTask)
- delete confirmTask;
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPConfirmUsers::ClassName (void)
- {
- return "CPPConfirmUsers";
- }
-
- /*-----------------------------------------------------------------*/
-
- void ConfirmCompletionProc (CPPObject *TheTask)
- /* This routine will be called when a 'confirm' task completes;*/
- /* It's job is to delete the node from the list if the confirm */
- /* task returns 'not here' */
- {
- CPPConfirmTask *CTask = (CPPConfirmTask *)TheTask;
- Str255 STemp;
- StringPtr UsersName;
- Boolean done = FALSE;
-
- // get the name of the connection we are confirming
- UsersName = ShortName (CTask->NodeToConfirm);
-
- if (!CTask->NodeExists(&done))
- {
- gUserList->DeleteUser(CTask->NodeToConfirm);
- if (gPrefsInfo.playLogon)
- gLogonSound->PlaySound(TRUE);
- PStrCat (255, STemp, 2, "\pLost connection with ", UsersName);
- SetStatusMessage (STemp, TRUE);
- }
-
- NukePtr(UsersName);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmUsers::DoPeriodicAction (void)
- /* if the confirm has completed, advance to the next node and */
- /* start another confirm */
- {
- CPPNodeInfo *TheNode = NULL;
- Str255 STemp;
- StringPtr UsersName;
-
- // call the inherited method to update frequency count
- CPPPeriodicTask::DoPeriodicAction();
-
- if (confirmTask->hasCompleted)
- {
- this->whichNode++;
- if (this->whichNode <= gUserList->GetNumItems())
- {
- TheNode = (CPPNodeInfo *)((*gUserList)[whichNode]);
-
- // tell the user we are confirming this connection
- UsersName = ShortName (TheNode);
- PStrCat (255, STemp, 2, "\pSearching for ", UsersName);
- SetStatusMessage (STemp, TRUE);
- NukePtr(UsersName);
-
- // do the confirmation
- confirmTask->StartNodeConfirm(TheNode, ConfirmCompletionProc);
- }
- else
- {
- this->hasCompleted = TRUE;
- this->callResult = noErr;
- }
- }
- }
-
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmUsers::DoCompletedAction (void)
- {
- CPPPeriodicTask::DoCompletedAction();
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmUsers::StartConfirmUsers (CompletionProc DoProc)
- {
- if (!this->hasCompleted)
- return;
-
- // get rid of the old confirm task (if any)
- if (confirmTask)
- delete confirmTask;
-
- // set up the confirm task
- this->confirmTask = new CPPConfirmTask (this->ourManager, 120, FALSE);
-
- // note that we haven't completed yet
- SetCompletionProc(DoProc);
- this->hasCompleted = FALSE;
- this->whichNode = 0;
-
- // add ourselves to the periodic task queue
- this->ourManager->AddPeriodicTask(this);
- }
-